package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: yankaiyue
 * @Create: 2025/8/12 8:54
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;

    @RequestMapping("/getListProvice")
    public JSONObject getListProvice(){
        List<Map> list = orderInfoService.getListProvice();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray mapData = new JSONArray();
        for (Map map : list) {
            JSONObject object = new JSONObject();
            object.put("name",map.get("name"));
            object.put("value",map.get("total_amount"));
            mapData.add(object);
        }
        data.put("valueName","交易金额");
        data.put("mapData",mapData);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListLunBo")
    public JSONObject getListLunBo() {
        List<Map> list = orderInfoService.getListLunBo();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
        JSONObject columns1 = new JSONObject();
        columns1.put("name","序号");
        columns1.put("id","id");
        columns.add(columns1);
        JSONObject columns2 = new JSONObject();
        columns2.put("name","课程名称");
        columns2.put("id","course_name");
        columns.add(columns2);
        JSONObject columns3 = new JSONObject();
        columns3.put("name","考试人次");
        columns3.put("id","user_id");
        columns.add(columns3);
        JSONObject columns4 = new JSONObject();
        columns4.put("name","平均分");
        columns4.put("id","avg_score");
        columns.add(columns4);
        JSONObject columns5 = new JSONObject();
        columns5.put("name","平均用时");
        columns5.put("id","avg_duration");
        columns.add(columns5);
        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("course_name",map.get("course_name"));
            row.put("user_id",map.get("user_id"));
            row.put("avg_score",map.get("avg_score"));
            row.put("avg_duration",map.get("avg_duration"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
    @RequestMapping("/getListNumber")
    public JSONObject getListNumber() {
        List<Map> list = orderInfoService.getListNumber();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        for (Map map : list) {
            jsonObject.put("data",map.get("num"));
        }
        return jsonObject;
    }
    @RequestMapping("/getListRating")
    public JSONObject getListRating() {
        List<Map> list = orderInfoService.getListRating();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();
        JSONObject columns1 = new JSONObject();
        columns1.put("name","序号");
        columns1.put("id","id");
        columns.add(columns1);
        JSONObject columns2 = new JSONObject();
        columns2.put("name","课程名称");
        columns2.put("id","course_name");
        columns.add(columns2);
        JSONObject columns3 = new JSONObject();
        columns3.put("name","平均评分");
        columns3.put("id","avg_rating");
        columns.add(columns3);
        JSONObject columns4 = new JSONObject();
        columns4.put("name","评价人数");
        columns4.put("id","user_num");
        columns.add(columns4);
        JSONObject columns5 = new JSONObject();
        columns5.put("name","好评人数");
        columns5.put("id","good_num");
        columns.add(columns5);
        JSONObject columns6 = new JSONObject();
        columns6.put("name","好评率");
        columns6.put("id","good_lv");
        columns.add(columns6);
        data.put("columns",columns);
        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("id",map.get("id"));
            row.put("course_name",map.get("course_name"));
            row.put("avg_rating",map.get("avg_rating"));
            row.put("user_num",map.get("user_num"));
            row.put("good_num",map.get("good_num"));
            row.put("good_lv",map.get("good_lv"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
